package com.sayice.robotconflict.game.object.logic;

import cn.hutool.core.util.NumberUtil;
import com.sayice.robotconflict.game.Game;
import com.sayice.robotconflict.game.object.Robot;

import java.util.function.BiFunction;

/**
 * 简单获取函数
 *
 * @author shubing
 */
public enum SimpleGetFunc {
    GET_INT_VALUE((robot, params) -> NumberUtil.parseNumber((params[0]).toString()).intValue()),
    
    GET_DOUBLE_VALUE((robot, params) -> NumberUtil.parseNumber((params[0]).toString()).doubleValue()),
    
    GET_BOOL_VALUE((robot, params) -> (Boolean) params[0]),
    
    GET_ROBOT_ATTACK_RADIUS((robot, params) -> Game.ROBOT_ATTACK_RADIUS),
    
    GET_ROBOT_BLOOD((robot, params) -> robot.blood);
    
    private BiFunction<Robot, Object[], Comparable<? extends Comparable<?>>> fn;
    
    SimpleGetFunc(BiFunction<Robot, Object[], Comparable<? extends Comparable<?>>> fn) {
        this.fn = fn;
    }
    
    public <T extends Comparable<T>> T get(Robot robot, Object... params) {
        return (T) fn.apply(robot, params);
    }
}
